<?php
class SysAccountsForm extends BaseFormAdmin{
	public function configure(){
		parent::configure();
		
		/*
		 * Add properties
		 */
		$this->addName();
		$this->addLoginUser();
		$this->addLoginPassword();
		$this->addLoginPasswordConfirm();
		$this->addGroupID();
		$this->addEmail();
		
		
		/*
		 * Setting name of form
		 */
		$this->widgetSchema->setNameFormat('SysAccounts[%s]');
		$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
	}
	/*
	 * Name of group 1
	 */
	private function addName(){
		$this->setWidget('name', new sfWidgetFormInputText());
		$this->setValidator('name', new sfValidatorString(array('required' => true, 'max_length'=> 255),  array('required' =>__('error_name_required',null,'sys_account_group'), 'max_length' =>__('error_max_length',null,'table_list'))));
	}
	/*
	 * Login user 2
	 */
	private function addLoginUser(){
		$this->setWidget('login_user', new sfWidgetFormInputText());
		$this->setValidator('login_user', new sfValidatorString(array('required' => true, 'max_length'=> 255),  array('required' =>__('error_login_user_required',null,'sys_account_group'), 'max_length' =>__('error_max_length',null,'table_list'))));
	}
	/*
	 * Login Password 3
	 */
	private function addLoginPassword(){
		$this->setWidget('login_password', new sfWidgetFormInputPassword());
		$this->setValidator('login_password', new sfValidatorString(array('required' => true, 'max_length'=> 255),  array('required' =>__('error_password_required',null,'sys_account_group'), 'max_length' =>__('error_max_length',null,'table_list'))));
	}
	/*
	 * Confirm password 4
	 */
	private function addLoginPasswordConfirm(){
		$this->setWidget('login_password_confirm', new sfWidgetFormInputPassword());
		$this->setValidator('login_password_confirm', new sfValidatorString(array('required' => true, 'max_length'=> 255),  array('required' =>__('error_password_confirm_required',null,'sys_account_group'), 'max_length' =>__('error_max_length',null,'table_list'))));
	}
	/*
	 * Group id 5
	 */
	private function addGroupID(){
		$db_groups = new SysAccountGroups();
		$groups = $db_groups->filterList(array('filter_enabled' => 1));
		
		
		$arr_groups = array('-1'=> __('option_select', null, 'table_list'));
		$arr_key = array();
		foreach($groups as $key => $val){
			$arr_groups[$val['id']] = $val['name'];
			$arr_key[] = $val['id']; 
		}		
		$this->setWidget('group_id', new sfWidgetFormChoice(array('choices'=>$arr_groups,'expanded'=>false)));
		$this->setValidator('group_id', new sfValidatorChoice(array('choices'=>$arr_key)));
	}
	/*
	 * Email 6
	 */
	private function addEmail(){
		$this->setWidget('email', new sfWidgetFormInputText());
		$this->setValidator('email', new sfValidatorAnd(array(
							new sfValidatorString(array('max_length'=> 255)),
							new sfValidatorEmail(array(), array('invalid' => __('error_email_invalid',null,'contact')))
						)));
	}
}
